home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / tcl / itcl1_31.z / itcl1_31 / tcldev / itcl-1.3 / man / incrTcl.n next >
Encoding:
Text File  |  1993-09-23  |  27.0 KB  |  606 lines

  1. '\"
  2. '\" MAN PAGE:  [incr Tcl] - Object-oriented extensions for Tcl
  3. '\"   AUTHOR:  Michael J. McLennan
  4. '\"     SCCS:  @(#)incrTcl.n    1.3 (9/19/93)
  5. '\" ========================================================================
  6. '\"                 Copyright (c) 1993  AT&T Bell Laboratories
  7. '\" ========================================================================
  8. '\" Permission to use, copy, modify, and distribute this software and its
  9. '\" documentation for any purpose and without fee is hereby granted,
  10. '\" provided that the above copyright notice appear in all copies and that
  11. '\" both that the copyright notice and warranty disclaimer appear in
  12. '\" supporting documentation, and that the names of AT&T Bell Laboratories
  13. '\" any of their entities not be used in advertising or publicity
  14. '\" pertaining to distribution of the software without specific, written
  15. '\" prior permission.
  16. '\"
  17. '\" AT&T disclaims all warranties with regard to this software, including
  18. '\" all implied warranties of merchantability and fitness.  In no event
  19. '\" shall AT&T be liable for any special, indirect or consequential
  20. '\" damages or any damages whatsoever resulting from loss of use, data or
  21. '\" profits, whether in an action of contract, negligence or other
  22. '\" tortuous action, arising out of or in connection with the use or
  23. '\" performance of this software.
  24. '\" ========================================================================
  25. '\" 
  26. '\" Man page formatting taken from...
  27. '\" Copyright 1990 Regents of the University of California
  28. '\" Permission to use, copy, modify, and distribute this
  29. '\" documentation for any purpose and without fee is hereby
  30. '\" granted, provided that this notice appears in all copies.
  31. '\" The University of California makes no representations about
  32. '\" the suitability of this material for any purpose.  It is
  33. '\" provided "as is" without express or implied warranty.
  34. '\"
  35. .so man.macros
  36. '\"
  37. '\"    # CS - begin display of code example
  38. .de CS
  39. .RS
  40. .nf
  41. \f(CB
  42. ..
  43. '\"    # CE - end display of code example
  44. .de CE
  45. \fP
  46. .fi
  47. .RE
  48. ..
  49. .HS "[incr\ Tcl]" tcl
  50. .BS
  51. '\" Note:  do not modify the .SH NAME line immediately below!
  52. .SH NAME
  53. [incr\ Tcl] \- Object-oriented extensions to Tcl
  54. .SH SYNOPSIS
  55. \fBitcl_class \fIclassName\fR \fB{
  56. .ti +0.3i
  57. \fBinherit \fIbaseClass\fR ?\fIbaseClass\fR...?
  58. .sp 0.1i
  59. .ti +0.3i
  60. \fBconstructor \fIargs body\fR
  61. .ti +0.3i
  62. \fBdestructor \fIbody\fR
  63. .sp 0.1i
  64. .ti +0.3i
  65. \fBmethod \fIname args body\fR
  66. .ti +0.3i
  67. \fBproc \fIname args body\fR
  68. .sp 0.1i
  69. .ti +0.3i
  70. \fBpublic \fIvarName\fR ?\fIinit\fR? ?\fIconfig\fR?
  71. .ti +0.3i
  72. \fBprotected \fIvarName\fR ?\fIinit\fR?
  73. .ti +0.3i
  74. \fBcommon \fIvarName\fR ?\fIinit\fR?
  75. .br
  76. \fB}\fR
  77. .sp
  78. \fIclassName objName\fR ?\fIargs...\fR?
  79. .br
  80. \fIclassName\fR \fB#auto\fR ?\fIargs...\fR?
  81. .br
  82. \fIclassName\fR \fB::\fR \fIproc\fR ?\fIargs...\fR?
  83. .sp
  84. \fIobjName method\fR ?\fIargs...\fR?
  85. .sp
  86. \fBitcl_info classes ?\fIpattern\fR?
  87. .br
  88. \fBitcl_info objects ?\fIpattern\fR? ?\fB-class \fIclassName\fR? ?\fB-isa \fIclassName\fR?
  89. .sp
  90. \fICommands available within class methods/procs:\fR
  91. .br
  92. \fBglobal \fIvarName\fR ?\fIvarName...\fR?
  93. .br
  94. \fBprevious \fIcommand\fR ?\fIargs...\fR?
  95. .br
  96. \fBvirtual \fIcommand\fR ?\fIargs...\fR?
  97. .BE
  98.  
  99. .SH DESCRIPTION
  100. .PP
  101. \fB[incr\ Tcl]\fR provides object-oriented extensions to Tcl, much as
  102. C++ provides object-oriented extensions to C.  The emphasis of this
  103. work, however, is not to create a whiz-bang object-oriented
  104. programming environment.  Rather, it is to support more structured
  105. programming practices in Tcl without changing the flavor of the language.
  106. More than anything else, \fB[incr\ Tcl]\fR provides a means of
  107. encapsulating related procedures together with their shared data
  108. in a local namespace that is hidden from the outside world.
  109. It encourages better programming by promoting the object-oriented
  110. "library" mindset.  It also allows for code re-use through inheritance.
  111. .PP
  112. The fundamental construct in \fB[incr\ Tcl]\fR is the class definition.
  113. Each class acts as a template for actual objects that can be created.
  114. Each object in a class contains a unique bundle of data, including
  115. "public" and "protected" data members.  When execution takes place within
  116. the scope of the class, both types of data members are accessible.
  117. To the programmer working outside of the class scope\-using an object
  118. to build his application\-only public data members are accessible.
  119. Public members represent attributes that can be used to configure an
  120. object.  For example, the "-text" attribute in the usual Tk "\fBbutton\fR"
  121. widget could be thought of as a public member.  Protected members,
  122. on the other hand, reflect the inner workings of an object and are
  123. kept hidden from the outside world.  This insulates the programmer
  124. that uses a class from the details of its implementation.
  125. Classes can also define "common" data members that are shared by all
  126. objects in a class.  Like protected members, common members are only
  127. accessible within the scope of the class.  The class designer will
  128. often provide special class-level procedures or "procs" to manipulate
  129. common members.  Since these "procs" can be invoked without reference
  130. to any specific object, they have access to common members, but not
  131. to public or protected members.
  132. .PP
  133. Special procedures called "methods" are used to manipulate individual
  134. objects.  The use of methods should be familiar to any
  135. Tk programmer\-the "\fBbutton\fR" widget, for example, has methods
  136. such as "flash" and "invoke" that are used to control its behavior.
  137. These methods form a contract between the class designer
  138. and the application developer, completely specifying the list of
  139. functions that can be used to interact with objects in the class.
  140. The implementation details within each method, however, are left
  141. solely to the class designer.  The public interface says \fIwhat\fR
  142. an object will do but not \fIhow\fR it will do it.  Insulating the
  143. application developer from these details leaves the class designer
  144. free to change them at any time, without warning, and without affecting
  145. programs that rely on the class.  It is precisely this encapsulation
  146. that makes object-oriented programs easier to understand and maintain.
  147. .PP
  148. The fact that \fB[incr\ Tcl]\fR objects look like Tk widgets is no
  149. accident.  \fB[incr\ Tcl]\fR was designed this way, to blend naturally
  150. into a Tcl/Tk application.  But \fB[incr\ Tcl]\fR extends the Tk paradigm
  151. from being merely object-based to being fully object-oriented.
  152. An object-oriented system supports inheritance, allowing classes to
  153. share common behaviors by inheriting them from an ancestor or
  154. base class.  Having a base class as a common abstraction allows
  155. a programmer to treat related classes in a similar manner.  For
  156. example, a toaster and a blender perform different (specialized)
  157. functions, but both share the abstraction of being appliances.
  158. By abstracting common behaviors into a base class, code can be
  159. \fIshared\fR rather than \fIcopied\fR.  The resulting application
  160. is easier to understand and maintain, and derived classes (e.g.,
  161. specialized appliances) can be added or removed more easily.
  162. .PP
  163. This description was merely a brief overview of object-oriented
  164. programming and \fB[incr\ Tcl]\fR.  A more tutorial introduction is
  165. presented in the paper included with this distribution.  Further
  166. details are presented in reference form below.
  167.  
  168. .SH SCOPE
  169. .PP
  170. Each class maintains its own local scope, separate from the main
  171. interpreter.  Within the scope of a class, all members\-including
  172. methods and procs, as well as public, protected and common
  173. variables\-can be accessed transparently.  In other words,
  174. methods and procs can be used like ordinary commands, and variables
  175. can be used without declaring them with anything like the Tcl
  176. "\fBglobal\fR" command.
  177. .PP
  178. The scope of a class extends to all derived classes as well, so members
  179. can be accessed transparently throughout a derivation hierarchy.
  180. If the same member name appears more than once in the hierarchy,
  181. the class with highest priority gets transparent access to the simple
  182. member name, and all other members must be accessed using the explicit
  183. "\fIclass\fR::\fImember\fR" syntax.  Priority is determined by the
  184. list of classes as reported by the "\fBinfo heritage\fR" command.
  185. .PP
  186. If a command is not recognized in a particular class scope, it is
  187. passed up the derivation hierarchy for evaluation.  Again, base classes
  188. are consulted in the order reported by the "\fBinfo heritage\fR"
  189. command.
  190. If a command is not recognized by any class in the hierarchy, it is
  191. passed out to the global scope (main interpreter) for evaluation.
  192. This scheme allows Tk widget commands, for example, to be accessed
  193. transparently within any class, but to be executed (as they should be)
  194. in the global scope.  Any command can be sent explicitly to the global
  195. scope using the "::\fIcommand\fR" syntax.
  196. .PP
  197. It is sometimes convenient, particularly when dealing with Tk widgets,
  198. to have access to global variables that exist in the main interpreter.
  199. This is achieved using the usual Tcl "\fBglobal\fR" command
  200. within a class method or proc.
  201.  
  202. .SH ARGUMENT LISTS
  203. .PP
  204. Class methods and procs look like ordinary Tcl procs, except that they
  205. also provide transparent access to class data.  The rules for handling
  206. formal arguments in the \fIargs\fR lists are the same as well.  Each
  207. element of this list can be a simple argument name, or another list
  208. containing the argument name and its default value.  If the last formal
  209. argument is named "args", it will absorb all unmatched arguments into
  210. a single list of values.
  211. .PP
  212. Argument lists for class methods also recognize a special argument to
  213. handle configuration of public variables.  If the last formal argument
  214. is named "config", it will absorb all unmatched arguments and parse
  215. them as "\-\fIvarName value\fR" assignments.  If \fIvarName\fR is
  216. recognized as a public variable, then this variable is modified to
  217. contain the given value.  If the variable was defined with special
  218. \fIconfig\fR code, this code is automatically executed in the scope
  219. of its associated class.  If this \fIconfig\fR code returns an error,
  220. the variable
  221. is automatically reset to its previous value, and the method is aborted,
  222. returning the configuration error.  If argument parsing is successful,
  223. the "config" variable is set to the list of variables that were
  224. configured, and the method body is executed.
  225. .PP
  226. As an example, suppose that we define a simple class with two public
  227. variables:
  228. .CS
  229. itcl_class Thing {
  230.     constructor {config} {}
  231.     method configure {config} {}
  232.  
  233.     public foo "" { puts stdout "-- just modified foo: $foo" }
  234.     public bar "" { puts stdout "-- just modified bar: $bar" }
  235. }
  236. .CE
  237. Both the constructor and the "configure" method contain the special
  238. "config" formal argument.  Thus, either of these methods can be used
  239. to configure the public variables:
  240. .CS
  241. wish: Thing x -foo 1 -bar 2
  242. -- just modified foo: 1
  243. -- just modified bar: 2
  244. x
  245. wish: x configure -bar 3
  246. -- just modified bar: 3
  247. .CE
  248. Each time "foo" or "bar" is configured in this example, its special
  249. \fIconfig\fR code (last argument in the "public" declaration) is executed,
  250. printing a message to show the updated value.
  251.  
  252. .SH CLASS DEFINITIONS
  253. .TP
  254. \fBitcl_class \fIclassName definition\fR
  255. Provides the definition for a class named \fIclassName\fR.  If
  256. \fIclassName\fR is already defined, then this command returns
  257. an error.  If the class definition is successfully parsed,
  258. \fIclassName\fR becomes a command in the interpreter, handling the
  259. creation of objects and providing access to class scope.
  260. The class \fIdefinition\fR
  261. is evaluated as a series of Tcl statements that configure the interpreter
  262. managing a particular class scope.  In addition to the usual
  263. commands, the following class definition commands are recognized:
  264. .RS
  265. .TP
  266. \fBinherit \fIbaseClass\fR ?\fIbaseClass\fR...?
  267. Declares one or more base classes, causing the current class to
  268. inherit their characteristics.  Classes must have been defined by
  269. a previous "\fBitcl_class\fR" command, or must be available to the
  270. auto-loading facility (see "AUTO-LOADING" below).  A single class
  271. definition can contain no more than one "\fBinherit\fR" command.
  272. .RS
  273. .LP
  274. When the same member name appears in two or more base classes,
  275. the base class that appears first in the "\fBinherit\fR" list takes
  276. precedence.  For example, if classes "Foo" and "Bar" both contain
  277. the member "x", then the "\fBinherit\fR" statement:
  278. .CS
  279. inherit Foo Bar
  280. .CE
  281. allows "Foo::x" to be accessed simply as "x" but forces "Bar::x" (and
  282. all other inherited members named "x") to be referenced with their
  283. explicit "\fIclass\fR::\fImember\fR" name.
  284. .RE
  285. .TP
  286. \fBconstructor \fIargs body\fR
  287. Declares the argument list and body used for the constructor, which
  288. is automatically invoked whenever an object is created.  If construction
  289. is successful, the constructor always returns the object name\-regardless
  290. of how the \fIbody\fR is defined\-and the object name becomes a command
  291. in the main interpreter.  If construction fails, an error message is
  292. returned.
  293. .RS
  294. .LP
  295. Like any other method, the constructor can be inherited
  296. from a base class.  Furthermore, any base class constructor that is
  297. not explicitly invoked within \fIbody\fR will be implicitly invoked
  298. by \fB[incr\ Tcl]\fR in the order that the base classes are reported
  299. in the "\fBinfo heritage\fR" command.  This ensures that all base classes
  300. are properly constructed.
  301. .RE
  302. .TP
  303. \fBdestructor \fIbody\fR
  304. Declares the body used for the destructor, which is automatically invoked
  305. whenever an object is deleted.  If the destructor is successful, the object
  306. data is destroyed and the object name is removed as a command from the
  307. main interpreter.  If destruction fails, an error message is returned
  308. and the object remains.
  309. .RS
  310. .LP
  311. Like any other method, the destructor can be inherited from a base class.
  312. Furthermore, any base class destructor that is not explicitly invoked
  313. within \fIbody\fR will be implicitly invoked by \fB[incr\ Tcl]\fR, in the
  314. \fIreverse\fR order compared to constructors.
  315. .RE
  316. .TP
  317. \fBmethod \fIname args body\fR
  318. Declares a method called \fIname\fR with an argument list \fIargs\fR
  319. and a \fIbody\fR of Tcl statements.  A method is just like the usual
  320. Tcl "proc" except that it has transparent access to public, protected
  321. and common variables.  Within the class scope, a method can be invoked
  322. like any other command\-simply by using its name.  In the
  323. external interpreter, the method name must be prefaced by an object
  324. name.  Methods in a base class that are redefined in the current class
  325. or hidden by another base class can be explicitly scoped using the
  326. "\fIclass\fR::\fImethod\fR" syntax.
  327. .TP
  328. \fBproc \fIname args body\fR
  329. Declares a proc called \fIname\fR with an argument list \fIargs\fR
  330. and a \fIbody\fR of Tcl statements.  A proc is similar to a method,
  331. except that it can be invoked without referring to a specific object,
  332. and therefore has access only to common variables\-not to public or
  333. protected variables.  Within the class scope, a proc can be invoked
  334. like any other command\-simply by using its name.  In the
  335. external interpreter, the proc is invoked using the \fIclassName\fR
  336. command "\fIclassName\fR :: \fIproc\fR" to access the class scope
  337. (see below).  Procs in a base class that are redefined in the current
  338. class or hidden by another base class can be explicitly scoped using
  339. the "\fIclass\fR::\fIproc\fR" syntax.
  340. .TP
  341. \fBpublic \fIvarName\fR ?\fIinit\fR? ?\fIconfig\fR?
  342. Declares a public variable named \fIvarName\fR.  Public variables are
  343. visible in methods within the scope of their class and any derived class.
  344. In addition, they can be modified outside of the class scope using the special
  345. "config" formal argument (see "ARGUMENT LISTS" above).  If the optional
  346. \fIinit\fR is specified, it is used as the initial value of the variable
  347. when a new object is created.  If the optional \fIconfig\fR command
  348. is specified,
  349. it is invoked whenever a public variable is modified via the "config"
  350. formal argument; if the \fIconfig\fR command returns an error, the
  351. public variable is reset to its value before configuration, and the
  352. method handling the configuration returns an error.
  353. .TP
  354. \fBprotected \fIvarName\fR ?\fIinit\fR?
  355. Declares a protected variable named \fIvarName\fR.  Protected variables
  356. are visible in methods within the scope of their class and any derived class,
  357. but cannot
  358. be modified outside of the class scope.  If the optional \fIinit\fR
  359. is specified, it is used as the initial value of the variable when a new
  360. object is created.  Initialization forces the variable to be a simple
  361. scalar value; uninitialized variables, on the other hand, can be used
  362. as arrays.  All objects have a built-in protected variable named
  363. "this" which is initialized to the instance name for the object.
  364. .TP
  365. \fBcommon \fIvarName\fR ?\fIinit\fR?
  366. Declares a common variable named \fIvarName\fR.  Common variables are
  367. shared among all objects in a class.  They are visible in methods and
  368. procs in the scope of their class and any derived class, but cannot be
  369. modified outside of the class scope.
  370. If the optional \fIinit\fR is specified, it is used as the
  371. initial value of the variable.  Initialization forces the variable to be
  372. a simple scalar value; uninitialized variables, on the other hand, can
  373. be used as arrays.
  374. .RS
  375. .LP
  376. Once a common variable has been declared, it can be configured using
  377. ordinary Tcl code within the class definition.  This facility is
  378. particularly useful when the initialization of the variable is
  379. non-trivial\-when the variable contains an array of values, for example:
  380. .CS
  381. itcl_class Foo {
  382.      .
  383.      .
  384.     common boolean
  385.     set boolean(true) 1
  386.     set boolean(false) 0
  387. }
  388. .CE
  389. .RE
  390. .RE
  391.  
  392. .SH CLASS USAGE
  393. .PP
  394. When a class definition has been loaded (or made available to the
  395. auto-loader), it can be used as a command in the main interpreter:
  396. .TP
  397. \fIclassName objName\fR ?\fIargs...\fR?
  398. Creates a new object in class \fIclassName\fR with the name \fIobjName\fR.
  399. Remaining arguments are passed to the constructor.  If construction is
  400. successful, the object name is returned and this name becomes a command
  401. in the main interpreter.  Otherwise, an error is returned.
  402. .TP
  403. \fIclassName\fR #auto ?\fIargs...\fR?
  404. Creates a new object in class \fIclassName\fR with an automatically
  405. generated name.  Names are of the form \fIclassName<number>\fR, e.g.,
  406. Toaster0, Toaster1, etc.  Remaining arguments are passed to the constructor.
  407. If construction is successful, the object name is returned and this name
  408. becomes a command in the main interpreter.  Otherwise, an error is returned.
  409. .TP
  410. \fIclassName\fR  ::  \fIproc\fR ?\fIargs...\fR?
  411. Used at the global scope to invoke a class proc named \fIproc\fR.
  412. Class procs are like ordinary Tcl procs, except that they are executed
  413. in the scope of the class and therefore have transparent
  414. access to common data members.
  415. .RS
  416. .LP
  417. Notice that, unlike any other scope qualifier in \fB[incr\ Tcl]\fR, the "::"
  418. shown above is surrounded by spaces.  This is necessary to avoid
  419. polluting the global namespace with every possible "\fIclass\fR::\fIproc\fR"
  420. command.
  421. .VS
  422. In Release 1.1, a special version of the usual "unknown" proc was provided
  423. to recognize commands like "\fIclass\fR::\fIproc\fR" (without spaces around
  424. the "::" qualifier).  This facility was unpopular, and is no longer supported.
  425. When class procs are invoked from the main interpreter, the "::" qualifier
  426. must be surrounded by spaces.
  427. .VE
  428. .RE
  429.  
  430. .SH OBJECT USAGE
  431. .TP
  432. \fIobjName method\fR ?\fIargs...\fR?
  433. Invokes a method named \fImethod\fR to operate on the specified object.
  434. Remaining arguments are passed to the method.  The method name can
  435. be "constructor", "destructor", any method name appearing in the
  436. class definition, or any of the following built-in methods.
  437. .SH BUILT-IN METHODS
  438. .TP
  439. \fIobjName\fR \fBisa \fIclassName\fR
  440. Returns non-zero if the given \fIclassName\fR can be found in the
  441. object's heritage, and zero otherwise.
  442. .TP
  443. \fIobjName\fR \fBdelete\fR
  444. Invokes the destructor associated with an object.
  445. If the destructor is successful, data associated with the object is
  446. deleted and \fIobjName\fR is removed from the commands in the main
  447. interpreter.  Returns the empty string, regardless of the destructor
  448. body.
  449. .TP
  450. \fIobjName\fR \fBinfo \fIoption\fR ?\fIargs...\fR?
  451. .TP
  452. \fIclassName\fR :: \fBinfo \fIoption\fR ?\fIargs...\fR?
  453. Returns information related to the class definition, or information
  454. concerning the interpreter that implements the class scope.  The
  455. \fIoption\fR parameter includes the following things, as well as
  456. the options recognized by the usual Tcl "info" command:
  457. .RS
  458. .TP
  459. \fIobjName\fR \fBinfo class\fR
  460. Returns the class name at the current class scope.  When prefaced
  461. by the object name, this command executes in the most-specific
  462. class scope, and therefore returns the most-specific class name.
  463. .TP
  464. \fIobjName\fR \fBinfo inherit\fR
  465. Returns the list of base classes as they were defined in the
  466. "\fBinherit\fR" command, or an empty string if this is a top-level class.
  467. .TP
  468. \fIobjName\fR \fBinfo heritage\fR
  469. Returns the current class name and the entire list of base classes in
  470. the order that they are traversed for object construction or member
  471. lookup.
  472. .TP
  473. \fIobjName\fR \fBinfo method\fR
  474. .TP
  475. \fIobjName\fR \fBinfo method\fR \fImethodName\fR ?\fB-args\fR? ?\fB-body\fR?
  476. In the first form, this command returns a list of all class methods.
  477. In the second form, it returns information for a specific method.
  478. If neither of the optional \fB-args\fR or \fB-body\fR flags is specified,
  479. a complete method definition is returned as a list of three elements
  480. including the method name, argument list and body.  Otherwise, the
  481. requested information is returned without the method name.
  482. If the \fImethodName\fR is not recognized, an empty string is returned.
  483. .TP
  484. \fIobjName\fR \fBinfo public\fR
  485. .TP
  486. \fIobjName\fR \fBinfo public\fR \fIvarName\fR ?\fB-init\fR? ?\fB-value\fR? ?\fB-config\fR?
  487. In the first form, this command returns a list of all public variables.
  488. In the second form, it returns information for a specific public variable.
  489. If none of the optional \fB-init\fR, \fB-value\fR or \fB-config\fR flags
  490. are specified, all available information is returned as a list of four
  491. elements including the variable name, initial value, current value,
  492. and configuration commands.  Otherwise, the requested information is
  493. returned without the variable name.
  494. If the \fIvarName\fR is not recognized, an empty string is returned.
  495. .TP
  496. \fIobjName\fR \fBinfo protected\fR
  497. .TP
  498. \fIobjName\fR \fBinfo protected\fR \fIvarName\fR ?\fB-init\fR? ?\fB-value\fR?
  499. In the first form, this command returns a list of all protected variables.
  500. In the second form, it returns information for a specific protected variable.
  501. If neither of the optional \fB-init\fR or \fB-value\fR flags is specified,
  502. all available information is returned as a list of three elements
  503. including the variable name, initial value and current value.
  504. Otherwise, the requested information is returned without the variable name.
  505. If the \fIvarName\fR is not recognized, an empty string is returned.
  506. .TP
  507. \fIobjName\fR \fBinfo common\fR
  508. .TP
  509. \fIobjName\fR \fBinfo common\fR \fIvarName\fR ?\fB-init\fR? ?\fB-value\fR?
  510. In the first form, this command returns a list of all common variables.
  511. In the second form, it returns information for a specific common variable.
  512. If neither of the optional \fB-init\fR or \fB-value\fR flags is specified,
  513. all available information is returned as a list of three elements
  514. including the variable name, initial value and current value.
  515. Otherwise, the requested information is returned without the variable name.
  516. If the \fIvarName\fR is not recognized, an empty string is returned.
  517. .RE
  518. .SH CLASS/OBJECT INFORMATION
  519. .PP
  520. The following commands are available at the global scope to query
  521. information about classes and objects that have been created.
  522. .TP
  523. \fBitcl_info classes ?\fIpattern\fR?
  524. Returns a list of classes with names matching the string \fIpattern\fR
  525. according to the rules of the "\fBstring match\fR" command.  If the
  526. optional \fIpattern\fR is not specified, a list of all known classes
  527. is returned.
  528. .TP
  529. \fBitcl_info objects ?\fIpattern\fR? ?\fB-class \fIclassName\fR? ?\fB-isa \fIclassName\fR?
  530. Returns a list of objects with names matching the string \fIpattern\fR
  531. according to the rules of the "\fBstring match\fR" command.  If the
  532. optional \fIpattern\fR is not specified, a list of all known objects
  533. is returned.  If the optional "\fB-class\fR" parameter is specified,
  534. this list is restricted to objects whose most-specific class is
  535. \fIclassName\fR.  If the optional "\fB-isa\fR" parameter is specified,
  536. this list is further restricted to objects having the given \fIclassName\fR
  537. anywhere in their heritage.
  538. .SH OTHER BUILT-IN COMMANDS
  539. The following commands are also available within the scope of each class.
  540. They cannot be accessed from outside of the class as proper methods or
  541. procs; rather, they are useful inside the class when implementing its
  542. functionality.
  543. .TP
  544. \fBglobal \fIvarName\fR ?\fIvarName...\fR?
  545. Creates a link to one or more global variables in the main interpreter.
  546. This is useful when communicating with Tk widgets that rely on global
  547. variables.
  548. .TP
  549. \fBprevious \fIcommand\fR ?\fIargs...\fR?
  550. Invokes \fIcommand\fR in the scope of the most immediate base class
  551. .VS
  552. (i.e., the "previous" class) for the object.  For classes using single
  553. .VE
  554. inheritance, this facility can be used to avoid hard-wired base class
  555. references of the form "\fIclass\fR::\fIcommand\fR", making code easier
  556. to maintain.  For classes using multiple inheritance, the utility of
  557. this function is dubious.
  558. If the class at the relevant scope has no base class, an error is returned.
  559. .VS
  560. .TP
  561. \fBvirtual \fIcommand\fR ?\fIargs...\fR?
  562. Invokes \fIcommand\fR in the scope of the most-specific class for the
  563. object.  This provides a way of accessing "virtual" functions from
  564. within class methods.  Normally, the commands at a certain class scope
  565. refer to methods/procs in that class or in less-specific base classes
  566. upward in the hierarchy.  The \fBvirtual\fR command moves the scope
  567. \fIdownward\fR to the most-specific class in the hierarchy, and then
  568. invokes the method.  If a class has methods that are redefined in
  569. derived classes, this causes the most-specific method to be invoked.
  570. Note that this is only needed when commands are invoked from within a
  571. class; when commands are invoked at the global scope, they are
  572. automatically executed in the scope of the most-specific class.
  573. .VE
  574.  
  575. .SH AUTO-LOADING
  576. .PP
  577. Class definitions need not be loaded explicitly; they can be loaded as
  578. needed by the usual Tcl auto-loading facility.  Each directory containing
  579. class definition files should have an accompanying "tclIndex" file.
  580. Each line in this file identifies a Tcl procedure \fIor [incr\ Tcl]
  581. class definition\fR and the file where the definition can be found.
  582. .PP
  583. For example, suppose a directory contains the definitions for classes
  584. "Toaster" and "SmartToaster".  Then the "tclIndex" file for this
  585. directory would look like:
  586. .CS
  587. # Tcl autoload index file: each line identifies a Tcl
  588. # procedure or [incr Tcl] class and the file where that
  589. # entity is defined.
  590. Toaster Toaster.tcl
  591. SmartToaster SmartToaster.tcl
  592. .CE
  593. The auto-loader must be made aware of this directory by appending
  594. the directory name to the "auto_path" variable.  When this is in
  595. place, classes will be auto-loaded as needed when used in an
  596. application.
  597. .PP
  598. Note that the usual "auto_mkindex" procedure used to generate the
  599. "tclIndex" file does not, by default, recognize \fB[incr\ Tcl]\fR
  600. class definitions; however, it can be modified to do so.  Such a
  601. modification is included in the "library" directory in the usual
  602. distribution for \fB[incr\ Tcl]\fR.
  603.  
  604. .SH KEYWORDS
  605. object-oriented, class
  606.